<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE MagicHash, UnliftedFFITypes #-}</span><span>
</span><span id="line-2"></span><span>
</span><span id="line-3"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-4"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- Module      :  Data.Array.IO</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow 2001</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-8"></span><span class="hs-comment">--</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Stability   :  experimental</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Portability :  non-portable (uses Data.Array.MArray)</span><span>
</span><span id="line-12"></span><span class="hs-comment">--</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- Mutable boxed and unboxed arrays in the IO monad.</span><span>
</span><span id="line-14"></span><span class="hs-comment">--</span><span>
</span><span id="line-15"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-16"></span><span>
</span><span id="line-17"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Data.Array.IO</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-18"></span><span>    </span><span class="annot"><span class="hs-comment">-- * @IO@ arrays with boxed elements</span></span><span>
</span><span id="line-19"></span><span>    </span><span class="annot"><a href="../../base/src/GHC.IOArray.html#IOArray"><span class="hs-identifier">IOArray</span></a></span><span class="hs-special">,</span><span>             </span><span class="hs-comment">-- instance of: Eq, Typeable</span><span>
</span><span id="line-20"></span><span>
</span><span id="line-21"></span><span>    </span><span class="annot"><span class="hs-comment">-- * @IO@ arrays with unboxed elements</span></span><span>
</span><span id="line-22"></span><span>    </span><span class="annot"><a href="Data.Array.IO.Internals.html#IOUArray"><span class="hs-identifier">IOUArray</span></a></span><span class="hs-special">,</span><span>            </span><span class="hs-comment">-- instance of: Eq, Typeable</span><span>
</span><span id="line-23"></span><span>
</span><span id="line-24"></span><span>    </span><span class="annot"><span class="hs-comment">-- * Overloaded mutable array interface</span></span><span>
</span><span id="line-25"></span><span>    </span><span class="hs-keyword">module</span><span> </span><span class="annot"><a href="Data.Array.MArray.html"><span class="hs-identifier">Data.Array.MArray</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-26"></span><span>
</span><span id="line-27"></span><span>    </span><span class="annot"><span class="hs-comment">-- * Doing I\/O with @IOUArray@s</span></span><span>
</span><span id="line-28"></span><span>    </span><span class="annot"><a href="Data.Array.IO.html#hGetArray"><span class="hs-identifier">hGetArray</span></a></span><span class="hs-special">,</span><span>           </span><span class="hs-comment">-- :: Handle -&gt; IOUArray Int Word8 -&gt; Int -&gt; IO Int</span><span>
</span><span id="line-29"></span><span>    </span><span class="annot"><a href="Data.Array.IO.html#hPutArray"><span class="hs-identifier">hPutArray</span></a></span><span class="hs-special">,</span><span>           </span><span class="hs-comment">-- :: Handle -&gt; IOUArray Int Word8 -&gt; Int -&gt; IO ()</span><span>
</span><span id="line-30"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-31"></span><span>
</span><span id="line-32"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Array.Base.html"><span class="hs-identifier">Data.Array.Base</span></a></span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Array.IO.Internals.html"><span class="hs-identifier">Data.Array.IO.Internals</span></a></span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Array.MArray.html"><span class="hs-identifier">Data.Array.MArray</span></a></span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/System.IO.Error.html#"><span class="hs-identifier">System.IO.Error</span></a></span><span>
</span><span id="line-36"></span><span>
</span><span id="line-37"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Foreign.html#"><span class="hs-identifier">Foreign</span></a></span><span>
</span><span id="line-38"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Foreign.C.html#"><span class="hs-identifier">Foreign.C</span></a></span><span>
</span><span id="line-39"></span><span>
</span><span id="line-40"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/GHC.Exts.html#"><span class="hs-identifier">GHC.Exts</span></a></span><span>  </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">MutableByteArray#</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">RealWorld</span></span><span class="hs-special">)</span><span>
</span><span id="line-41"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.Handle.html#"><span class="hs-identifier">GHC.IO.Handle</span></a></span><span>
</span><span id="line-42"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.Exception.html#"><span class="hs-identifier">GHC.IO.Exception</span></a></span><span>
</span><span id="line-43"></span><span>
</span><span id="line-44"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-45"></span><span class="hs-comment">-- hGetArray</span><span>
</span><span id="line-46"></span><span>
</span><span id="line-47"></span><span class="hs-comment">-- | Reads a number of 'Word8's from the specified 'Handle' directly</span><span>
</span><span id="line-48"></span><span class="hs-comment">-- into an array.</span><span>
</span><span id="line-49"></span><span class="annot"><a href="Data.Array.IO.html#hGetArray"><span class="hs-identifier hs-type">hGetArray</span></a></span><span>
</span><span id="line-50"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span>               </span><span class="hs-comment">-- ^ Handle to read from</span><span>
</span><span id="line-51"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Array.IO.Internals.html#IOUArray"><span class="hs-identifier hs-type">IOUArray</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span>   </span><span class="hs-comment">-- ^ Array in which to place the values</span><span>
</span><span id="line-52"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>                  </span><span class="hs-comment">-- ^ Number of 'Word8's to read</span><span>
</span><span id="line-53"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>
</span><span id="line-54"></span><span>                </span><span class="hs-comment">-- ^ Returns: the number of 'Word8's actually</span><span>
</span><span id="line-55"></span><span>                </span><span class="hs-comment">-- read, which might be smaller than the number requested</span><span>
</span><span id="line-56"></span><span>                </span><span class="hs-comment">-- if the end of file was reached.</span><span>
</span><span id="line-57"></span><span>
</span><span id="line-58"></span><span id="hGetArray"><span class="annot"><span class="annottext">hGetArray :: Handle -&gt; IOUArray Int Word8 -&gt; Int -&gt; IO Int
</span><a href="Data.Array.IO.html#hGetArray"><span class="hs-identifier hs-var hs-var">hGetArray</span></a></span></span><span> </span><span id="local-6989586621679054295"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679054295"><span class="hs-identifier hs-var">handle</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Array.IO.Internals.html#IOUArray"><span class="hs-identifier hs-type">IOUArray</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Array.Base.html#STUArray"><span class="hs-identifier hs-type">STUArray</span></a></span><span> </span><span id="local-6989586621679054292"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054292"><span class="hs-identifier hs-var">_l</span></a></span></span><span> </span><span id="local-6989586621679054291"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054291"><span class="hs-identifier hs-var">_u</span></a></span></span><span> </span><span id="local-6989586621679054290"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054290"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span id="local-6989586621679054289"><span class="annot"><span class="annottext">MutableByteArray# RealWorld
</span><a href="#local-6989586621679054289"><span class="hs-identifier hs-var">ptr</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span id="local-6989586621679054288"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054288"><span class="hs-identifier hs-var">count</span></a></span></span><span>
</span><span id="line-59"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054288"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>              </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-60"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054288"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&lt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054288"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054290"><span class="hs-identifier hs-var">n</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; String -&gt; Int -&gt; IO Int
forall a. Handle -&gt; String -&gt; Int -&gt; IO a
</span><a href="Data.Array.IO.html#illegalBufferSize"><span class="hs-identifier hs-var">illegalBufferSize</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679054295"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetArray&quot;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054288"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-61"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-62"></span><span>      </span><span class="hs-comment">-- we would like to read directly into the buffer, but we can't</span><span>
</span><span id="line-63"></span><span>      </span><span class="hs-comment">-- be sure that the MutableByteArray# is pinned, so we have to</span><span>
</span><span id="line-64"></span><span>      </span><span class="hs-comment">-- allocate a separate area of memory and copy.</span><span>
</span><span id="line-65"></span><span>      </span><span class="annot"><span class="annottext">Int -&gt; (Ptr Any -&gt; IO Int) -&gt; IO Int
forall a b. Int -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="../../base/src/Foreign.Marshal.Alloc.html#allocaBytes"><span class="hs-identifier hs-var">allocaBytes</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054288"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Any -&gt; IO Int) -&gt; IO Int) -&gt; (Ptr Any -&gt; IO Int) -&gt; IO Int
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679054282"><span class="annot"><span class="annottext">Ptr Any
</span><a href="#local-6989586621679054282"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-66"></span><span>        </span><span id="local-6989586621679054281"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054281"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; Ptr Any -&gt; Int -&gt; IO Int
forall a. Handle -&gt; Ptr a -&gt; Int -&gt; IO Int
</span><a href="../../base/src/GHC.IO.Handle.Text.html#hGetBuf"><span class="hs-identifier hs-var">hGetBuf</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679054295"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Any
</span><a href="#local-6989586621679054282"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054288"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-67"></span><span>        </span><span class="annot"><span class="annottext">Ptr ()
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">MutableByteArray# RealWorld -&gt; Ptr Any -&gt; CSize -&gt; IO (Ptr ())
forall a.
MutableByteArray# RealWorld -&gt; Ptr a -&gt; CSize -&gt; IO (Ptr ())
</span><a href="Data.Array.IO.html#memcpy_ba_ptr"><span class="hs-identifier hs-var">memcpy_ba_ptr</span></a></span><span> </span><span class="annot"><span class="annottext">MutableByteArray# RealWorld
</span><a href="#local-6989586621679054289"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Any
</span><a href="#local-6989586621679054282"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CSize
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="../../base/src/GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054281"><span class="hs-identifier hs-var">r</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-68"></span><span>        </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054281"><span class="hs-identifier hs-var">r</span></a></span><span>
</span><span id="line-69"></span><span>
</span><span id="line-70"></span><span id="local-6989586621679054337"><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;memcpy&quot;</span></span><span>
</span><span id="line-71"></span><span>   </span><span id="memcpy_ba_ptr"><span class="annot"><a href="Data.Array.IO.html#memcpy_ba_ptr"><span class="hs-identifier hs-var">memcpy_ba_ptr</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">MutableByteArray#</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">RealWorld</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679054337"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/Foreign.C.Types.html#CSize"><span class="hs-identifier hs-type">CSize</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span></span><span>
</span><span id="line-72"></span><span>
</span><span id="line-73"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-74"></span><span class="hs-comment">-- hPutArray</span><span>
</span><span id="line-75"></span><span>
</span><span id="line-76"></span><span class="hs-comment">-- | Writes an array of 'Word8' to the specified 'Handle'.</span><span>
</span><span id="line-77"></span><span class="annot"><a href="Data.Array.IO.html#hPutArray"><span class="hs-identifier hs-type">hPutArray</span></a></span><span>
</span><span id="line-78"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span>                       </span><span class="hs-comment">-- ^ Handle to write to</span><span>
</span><span id="line-79"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.Array.IO.Internals.html#IOUArray"><span class="hs-identifier hs-type">IOUArray</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span>           </span><span class="hs-comment">-- ^ Array to write from</span><span>
</span><span id="line-80"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span>                          </span><span class="hs-comment">-- ^ Number of 'Word8's to write</span><span>
</span><span id="line-81"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-82"></span><span>
</span><span id="line-83"></span><span id="hPutArray"><span class="annot"><span class="annottext">hPutArray :: Handle -&gt; IOUArray Int Word8 -&gt; Int -&gt; IO ()
</span><a href="Data.Array.IO.html#hPutArray"><span class="hs-identifier hs-var hs-var">hPutArray</span></a></span></span><span> </span><span id="local-6989586621679054278"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679054278"><span class="hs-identifier hs-var">handle</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Array.IO.Internals.html#IOUArray"><span class="hs-identifier hs-type">IOUArray</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Array.Base.html#STUArray"><span class="hs-identifier hs-type">STUArray</span></a></span><span> </span><span id="local-6989586621679054277"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054277"><span class="hs-identifier hs-var">_l</span></a></span></span><span> </span><span id="local-6989586621679054276"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054276"><span class="hs-identifier hs-var">_u</span></a></span></span><span> </span><span id="local-6989586621679054275"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054275"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span id="local-6989586621679054274"><span class="annot"><span class="annottext">MutableByteArray# RealWorld
</span><a href="#local-6989586621679054274"><span class="hs-identifier hs-var">raw</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span id="local-6989586621679054273"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054273"><span class="hs-identifier hs-var">count</span></a></span></span><span>
</span><span id="line-84"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054273"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>              </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-85"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054273"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&lt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054273"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054275"><span class="hs-identifier hs-var">n</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; String -&gt; Int -&gt; IO ()
forall a. Handle -&gt; String -&gt; Int -&gt; IO a
</span><a href="Data.Array.IO.html#illegalBufferSize"><span class="hs-identifier hs-var">illegalBufferSize</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679054278"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hPutArray&quot;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054273"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-86"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-87"></span><span>      </span><span class="hs-comment">-- as in hGetArray, we would like to use the array directly, but</span><span>
</span><span id="line-88"></span><span>      </span><span class="hs-comment">-- we can't be sure that the MutableByteArray# is pinned.</span><span>
</span><span id="line-89"></span><span>     </span><span class="annot"><span class="annottext">Int -&gt; (Ptr Any -&gt; IO ()) -&gt; IO ()
forall a b. Int -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="../../base/src/Foreign.Marshal.Alloc.html#allocaBytes"><span class="hs-identifier hs-var">allocaBytes</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054273"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Any -&gt; IO ()) -&gt; IO ()) -&gt; (Ptr Any -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679054272"><span class="annot"><span class="annottext">Ptr Any
</span><a href="#local-6989586621679054272"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-90"></span><span>       </span><span class="annot"><span class="annottext">Ptr ()
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Any -&gt; MutableByteArray# RealWorld -&gt; CSize -&gt; IO (Ptr ())
forall a.
Ptr a -&gt; MutableByteArray# RealWorld -&gt; CSize -&gt; IO (Ptr ())
</span><a href="Data.Array.IO.html#memcpy_ptr_ba"><span class="hs-identifier hs-var">memcpy_ptr_ba</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Any
</span><a href="#local-6989586621679054272"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">MutableByteArray# RealWorld
</span><a href="#local-6989586621679054274"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CSize
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="../../base/src/GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054273"><span class="hs-identifier hs-var">count</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-91"></span><span>       </span><span class="annot"><span class="annottext">Handle -&gt; Ptr Any -&gt; Int -&gt; IO ()
forall a. Handle -&gt; Ptr a -&gt; Int -&gt; IO ()
</span><a href="../../base/src/GHC.IO.Handle.Text.html#hPutBuf"><span class="hs-identifier hs-var">hPutBuf</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679054278"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Any
</span><a href="#local-6989586621679054272"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054273"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-92"></span><span>
</span><span id="line-93"></span><span id="local-6989586621679054334"><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;memcpy&quot;</span></span><span>
</span><span id="line-94"></span><span>   </span><span id="memcpy_ptr_ba"><span class="annot"><a href="Data.Array.IO.html#memcpy_ptr_ba"><span class="hs-identifier hs-var">memcpy_ptr_ba</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679054334"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">MutableByteArray#</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">RealWorld</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/Foreign.C.Types.html#CSize"><span class="hs-identifier hs-type">CSize</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span></span><span>
</span><span id="line-95"></span><span>
</span><span id="line-96"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-97"></span><span class="hs-comment">-- Internal Utils</span><span>
</span><span id="line-98"></span><span>
</span><span id="line-99"></span><span id="local-6989586621679054344"><span class="annot"><a href="Data.Array.IO.html#illegalBufferSize"><span class="hs-identifier hs-type">illegalBufferSize</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621679054344"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-100"></span><span id="illegalBufferSize"><span class="annot"><span class="annottext">illegalBufferSize :: forall a. Handle -&gt; String -&gt; Int -&gt; IO a
</span><a href="Data.Array.IO.html#illegalBufferSize"><span class="hs-identifier hs-var hs-var">illegalBufferSize</span></a></span></span><span> </span><span id="local-6989586621679054267"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679054267"><span class="hs-identifier hs-var">handle</span></a></span></span><span> </span><span id="local-6989586621679054266"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679054266"><span class="hs-identifier hs-var">fn</span></a></span></span><span> </span><span id="local-6989586621679054265"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054265"><span class="hs-identifier hs-var">sz</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-101"></span><span>        </span><span class="annot"><span class="annottext">IOException -&gt; IO a
forall a. IOException -&gt; IO a
</span><a href="../../base/src/GHC.IO.Exception.html#ioException"><span class="hs-identifier hs-var">ioException</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IOException -&gt; String -&gt; IOException
</span><a href="../../base/src/System.IO.Error.html#ioeSetErrorString"><span class="hs-identifier hs-var">ioeSetErrorString</span></a></span><span>
</span><span id="line-102"></span><span>                     </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IOErrorType
-&gt; String -&gt; Maybe Handle -&gt; Maybe String -&gt; IOException
</span><a href="../../base/src/System.IO.Error.html#mkIOError"><span class="hs-identifier hs-var">mkIOError</span></a></span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="../../base/src/GHC.IO.Exception.html#InvalidArgument"><span class="hs-identifier hs-var">InvalidArgument</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679054266"><span class="hs-identifier hs-var">fn</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Handle -&gt; Maybe Handle
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679054267"><span class="hs-identifier hs-var">handle</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Maybe String
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-103"></span><span>                     </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;illegal buffer size &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; String -&gt; String
forall a. Show a =&gt; Int -&gt; a -&gt; String -&gt; String
</span><a href="../../base/src/GHC.Show.html#showsPrec"><span class="hs-identifier hs-var">showsPrec</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">9</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054265"><span class="hs-identifier hs-var">sz</span></a></span><span class="hs-glyph">::</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span class="hs-special">)</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-104"></span></pre></body></html>